﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using TodayWhoModel;
using System.Web.Services;


namespace TodayWho
{
    public partial class fbregister : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                if (Session["userId"] == null)
                {
                    Response.Redirect("home.aspx");
                }
            }
        }

        protected void btnSave_OnClick(object sender, EventArgs e)
        {
            UserModel user = new UserModel();
            user.UserId = Int32.Parse(Session["userId"].ToString());
            user.UserName = txtUserName.Text.Trim();
            user.CategoryId = Int32.Parse(ddListCategory.SelectedValue);

            if (user.UpdateUserNameAndCategory())
            {
                user.FbIsComplete = true;
                user.UpdateFBComplete();
                Session.Remove("userName");
                Session.Add("userName", user.UserName);
                Session.Add("categoryId", user.CategoryId);
                Response.Redirect("profile.aspx?u=" + user.UserName);
            }
            else
            {
                lblError.Text = "Bu kullanıcı adı kullanılmaktadır.";
                lblError.Visible = true;
            }

        }
    }
}